﻿using System;
using System.Collections.Generic;
using System.Text;

namespace leetcode_learning.Common
{
    /// <summary>
    /// 用两个栈实现队列
    /// </summary>
    public class CQueue
    {
        private Stack<int> InStack;
        private Stack<int> OutStack;

        public CQueue()
        {
            InStack = new Stack<int>();
            OutStack = new Stack<int>();
        }

        public void AppendTail(int value)
        {
            InStack.Push(value);

        }

        public int DeleteHead()
        {
            if (InStack.Count == 0)
                return -1;
            if (InStack.Count == 1)
                return InStack.Pop();
            while (InStack.Count > 0)
            {
                OutStack.Push(InStack.Pop());
            }

            var res = OutStack.Pop();

            while (OutStack.Count > 0)
            {
                InStack.Push(OutStack.Pop());
            }
            return res;
        }
    }
}
